package two.dimensional.arrays;

/**
 * @author shkstart
 * @date 2022/4/17 - 16:34
 */
public class YangHui {
    public static void main(String[] args) {
//        int yangHui[][] = new int[10][];
//        for (int i = 0; i < yangHui.length; i++ ) {
//            for (int j = 0; j <= yangHui.length; j++ ) {
//                if (i == 1 && j == 0 ) {
//                    yangHui[i][j] = 1;
//                }else if ( i == j ) {
//                    yangHui[i][j] = 1;
//                }else {
//                    yangHui[i][j] = yangHui[i-1][j-1] + yangHui[i-1][j];
//                }
//                System.out.println(yangHui[i][j] + " ");
//            }
//            System.out.println();
//        }

//        以上为错误示范 自己打的我哭死

//        以下为老师的思路
        int yangHui[][] = new int[10][];

        for (int i = 0; i < yangHui.length; i++ ) {
            yangHui[i] = new int[i + 1];

            yangHui[i][0] = yangHui[i][i] = 1;

            if ( i > 1 ) {
                for (int j = 1; j < yangHui[i-1].length; j++ ) {
                    yangHui[i][j] = yangHui[i-1][j-1] + yangHui[i-1][j];
                }
            }
        }

        for (int i = 0; i < yangHui.length; i++ ) {
            for (int j = 0; j < yangHui[i].length; j++ ) {
                System.out.print(yangHui[i][j] + " ");
            }
            System.out.println();
        }


    }
}
